<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function xiaoliu(method, url) {
        return new Promise((resolve, reject) => {
          let xhr = new XMLHttpRequest();
          xhr.open(method, url, true); //创建与服务器的链接
          xhr.send(); //发送请求
          xhr.onreadystatechange = function () {
            //等待后台响应
            if (xhr.readyState == 4) {
              if (xhr.status == 200) {
                // 拿到数据
                console.log(JSON.parse(xhr.responseText));
                resolve(xhr.responseText);
              } else {
                reject("error");
              }
            }
          };
        });
      }
      xiaoliu("get", "/aa.json").then((res) => {
        console.log(res);
      });
      // 首先创建一个xhr对象
    </script>
  </body>
</html>
